import { app, Menu, Tray } from "electron";
import { getIsAutoRunning, setAutoRunningStatus } from "../utils/tools";

export const createSysTray = () => {
    let tray = new Tray("resource/logo.png");
    const contextMenu = Menu.buildFromTemplate([
        {
            label: "显示",
            click: function () {
                app.show();
            },
        },
        {
            label: "隐藏",
            click: function () {
                app.hide();
            },
        },
        {
            label: "退出",
            click: function () {
                app.quit();
            },
        },
        {
            label: "开机启动",
            type: "checkbox",
            checked: getIsAutoRunning(),
            click(e) {
                setAutoRunningStatus(e.checked);
            },
        },
    ]);

    tray.setToolTip("应用标题");
    tray.setContextMenu(contextMenu);
};

export const createMenu = () => {
    const menu = Menu.buildFromTemplate([
        {
            label: "原生应用菜单演示",
            submenu: [
                {
                    label: "test1",
                },
                {
                    type: "separator",
                },
                {
                    label: "test2",
                },
            ],
        },
    ]);
    Menu.setApplicationMenu(menu);
};
